<template>
  <div>
    <el-card class="box-card">
      <el-row :gutter="8"
              type="flex"
              align="middle">
        <el-col :span="1.5">
          分类
        </el-col>
        <el-col :span="3">
          <el-select size="small"
                     width="100px"
                     v-model="queryData.tyId"
                     placeholder="请选择">
            <template v-for="el in res">
              <el-option :key="el.id"
                         :label="el.name"
                         :value="el.id">
              </el-option>
            </template>

          </el-select>
        </el-col>
        <el-col :span="1.5">
          状态
        </el-col>
        <el-col :span="3">
          <el-select size="small"
                     width="100px"
                     v-model="queryData.sh"
                     placeholder="请选择">
            <el-option label="待审核"
                       :value="1">
            </el-option>

            <el-option label="通过"
                       :value="2">
            </el-option>
            <el-option label="驳回"
                       :value="3">
            </el-option>

          </el-select>
        </el-col>
        <el-col :span="1.5">
          <el-button size="mini"
                     type="primary"
                     icon="el-icon-search"
                     @click="getDate()">搜索</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button icon='el-icon-refresh'
                     size="mini"
                     @click="reset">重置</el-button>
        </el-col>
      </el-row>
      <el-table :data="tableData"
                v-loading="loading"
                style="width: 100%"
                :header-cell-style="{background:'#f8f8f9','text-align':'center'}"
                :cell-style="{'text-align':'center'}">
        <el-table-column type="selection"
                         width="120">
        </el-table-column>
        <el-table-column prop="tyName"
                         label="分类名称">
        </el-table-column>
        <el-table-column prop="uid"
                         label="用户id">
        </el-table-column>
        <el-table-column prop="comUser.realName"
                         label="用户名称">
        </el-table-column>
        <el-table-column prop="sh"
                         label="状态">
          <template slot-scope="scope">
            <span>{{scope.row.sh==1?'待审核':scope.row.sh==2?'通过':'驳回'}}</span>
          </template>
        </el-table-column>

        <el-table-column prop="bhly"
                         label="驳回理由">
        </el-table-column>
        <el-table-column label="操作">
          <template v-slot="data">
            <el-button icon="el-icon-edit"
                       type="text"
                       @click="updateHandler(data.row.id)">修改</el-button>
            <el-button icon="el-icon-delete"
                       type="text"
                       @click="deleteHandler(data.row.id)">删除</el-button>
          </template>

        </el-table-column>
      </el-table>
      <div class="page"
           v-show="total!=0">
        <el-pagination background
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       :current-page="queryData.pageNum"
                       :page-sizes="[3, 5, 7, 9]"
                       :page-size="queryData.pageSize"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total">
        </el-pagination>
      </div>
    </el-card>
    <div>
      <el-dialog title="修改相亲圈"
                 :visible.sync="dialogVisible"
                 width="30%">
        <el-form :model="formData"
                 ref="ruleForm"
                 label-width="80px">

          <el-form-item label="状态"
                        prop="ty">
            <el-select placeholder="请选择"
                       v-model="formData.sh">
              <el-option label="待审核"
                         :value="1">
              </el-option>
              <el-option label="通过"
                         :value="2">
              </el-option>
              <el-option label="驳回"
                         :value="3">
              </el-option>

            </el-select>
          </el-form-item>

          <el-form-item label="院校名称">
            <el-input size="small"
                      v-model="formData.xqqXb"
                      placeholder="院校名称"></el-input>
          </el-form-item>
          <el-form-item label="公职名称">
            <el-input size="small"
                      v-model="formData.xqqGz"
                      placeholder="公职名称"></el-input>
          </el-form-item>

          <el-form-item label="离异时长">
            <el-input size="small"
                      v-model="formData.xqqLl"
                      placeholder="离异时长"></el-input>
          </el-form-item>
          <el-form-item label="颜值得分">
            <el-input size="small"
                      v-model="formData.xqqYz"
                      placeholder="颜值得分"></el-input>
          </el-form-item>
          <el-form-item label="职位名称">
            <el-input size="small"
                      v-model="formData.xqqBl"
                      placeholder="职位名称"></el-input>
          </el-form-item>
          <el-form-item v-if="formData.sh==3"
                        label="驳回理由">
            <el-input size="small"
                      v-model="formData.bhly"
                      placeholder="职位名称"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer"
              class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary"
                     @click="update">确 定</el-button>
        </span>
      </el-dialog>
    </div>

  </div>

</template>

<script>
export default {
  data() {
    return {
      queryData: {
        pageNum: 1,
        pageSize: 5,

        tyId: null,
        sh: null
      },
      loading: false,
      formData: {
        bhly: null,
        comUser: null,
        createBy: null,
        createTime: null,
        id: null,
        params: null,
        remark: null,
        searchValue: null,
        sh: null,
        tyId: null,
        tyName: null,
        uid: null,
        updateBy: null,
        updateTime: null,
        xqqBl: null,
        xqqGz: null,
        xqqLl: null,
        xqqXb: null,
        xqqYz: null
      },
      tableData: [],
      total: 0,
      res: [],
      dialogVisible: false
    }
  },
  mounted() {
    this.getDate()
  },
  methods: {
    async getDate() {
      this.loading = true
      let { data } = await this.$axios.get('com/xqq/list', { params: this.queryData })
      console.log(data)
      this.tableData = data.rows
      this.total = data.total
      this.loading = false
      let { data: res } = await this.$axios.get('com/xqqType/list2')
      this.res = res.data
    },
    handleSizeChange(val) {
      this.queryData.pageSize = val
      this.getDate()
    },
    handleCurrentChange(val) {
      this.queryData.pageNum = val
      this.getDate()
    },
    search() {
      this.getDate()
    },
    reset() {
      this.queryData.sh = null
      this.queryData.tyId = null
    },
    deleteHandler(id) {
      this.$confirm(`是否确认删除相亲圈类型编号为${id.toString()}的数据项?`, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          let data = await this.$axios.delete(`com/xqq/${id.toString()}`)
          console.log(data)
          if (data.data.code != 200) this.$message.error(data.data.msg)
          this.$message({
            type: 'success',
            message: data.data.msg
          })
          this.getDate()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    async updateHandler(id) {
      this.dialogVisible = true
      let { data } = await this.$axios.get(`com/xqq/${id}`)
      this.formData = data.data
    },
    async update() {
      let { data } = await this.$axios.put('com/xqq', this.formData)

      if (data.code != 200) return this.$message.error(data.msg)
      this.$message({
        message: data.msg,
        type: 'success'
      })
      this.dialogVisible = false
      this.getDate()
    }
  }
}
</script>

<style>
.page {
  margin-top: 15px;
  display: flex;
  justify-content: flex-end;
}
</style>